﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

namespace CleanBackupDLL
{
	static class Configuration
	{
		private const string CONFIG_PATH = "configuration.xml";

		static public BackupStatus Load()
		{
			BackupStatus bs = new BackupStatus();

			try
			{
				if (File.Exists(CONFIG_PATH))
				{
					XmlSerializer reader = new XmlSerializer(bs.GetType());
					StreamReader file = new StreamReader(CONFIG_PATH);

					bs = (BackupStatus)reader.Deserialize(file);
					file.Close();
				}
			}
			catch (Exception ex)
			{
				throw new Exception("Error at loading configuration.", ex.InnerException);
			}

			return bs;
		}

		static public void Save(BackupStatus bs)
		{
			XmlSerializer writer = new XmlSerializer(bs.GetType());
			StreamWriter file = new StreamWriter(CONFIG_PATH);

			writer.Serialize(file, bs);
			file.Close();
		}
	}
}
